﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smarly.Bussines.Model;

namespace Confcloud.Email.Templates
{
	public class SubscribeNewsEmail : EmailQueue<Confcloud.Email.Templates.SubscribeNewsEmail>
	{
		public new const string TemplateName = "SubscribeNews";

		#region Parameters

		public const string News = "NEWS";

		#endregion

		private readonly string _email;
		private readonly NewsModel _model;
/*
		private readonly Dictionary<BookTree, List<BookTree>> _books;
		private readonly List<string> _emails;

*/

		public SubscribeNewsEmail(string email, /*Dictionary<BookTree, List<BookTree>> books, List<string> emails*/NewsModel model)
			: base(TemplateName)
		{
			_email = email;
			_model = model;
/*
			_books = books;
			_emails = emails;
*/
		}


		#region Overrides of RestObject<ParticipantActivationEmail>

		public override Confcloud.Email.Templates.SubscribeNewsEmail Get()
		{
			throw new NotImplementedException();
		}

		public override Confcloud.Email.Templates.SubscribeNewsEmail Post()
		{
			base.Recipent = string.Format("{0}", _email);

			StringBuilder sb = new StringBuilder();
			foreach (BookTree section in _model.Sections.OrderByDescending(x => x.UpdateDate))
			{
				sb.AppendFormat(
					"<div style=\"clear:both;\"></div><div style=\"width: 100%;\"><div style=\"background: none repeat scroll 0px 0px #FFFFFF; border: 1px solid #C8C8C8; float: left; padding: 4px; margin: 0px;\"><img alt=\"{0}\" src=\"{1}\"></div><div style=\"margin-left: 100px;\"><dl><dt style=\"margin-bottom:4px\"><a style=\"color:#000000\" href=\"http://smarly.net{3}\">{2}</a></dt>", section.Parent.Text, section.Book.CoverUrl, section.Text, section.Url, section.Parent.Url);

				foreach (var child in section.Children)
				{
					sb.AppendFormat("<dd style=\"margin-bottom:4px;\"><a style=\"color:#000000\" href=\"http://smarly.net{1}\">{0}</a></dd>", child.Text, child.Url);
				}

				sb.Append("</dl></div></div>");
				sb.Append("<div style=\"clear:both;\"></div>");

			}
			AddParam(News, sb.ToString());
			return base.Post();
		}

		public override Confcloud.Email.Templates.SubscribeNewsEmail Put()
		{
			throw new NotImplementedException();
		}

		public override Confcloud.Email.Templates.SubscribeNewsEmail Delete()
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}